<template>
  <div class="app-container">
    <el-form :model="queryParam" ref="queryForm" size="small" :inline="true"  label-width="68px">
      <el-form-item label="字典名称" prop="dictName">
        <el-input
          v-model="queryParam.dictName"
          placeholder="请输入字典名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="btnSearch"
        />
      </el-form-item>
      <el-form-item label="字典类型" prop="dictType">
        <el-input
          v-model="queryParam.dictType"
          placeholder="请输入字典类型"
          clearable
          style="width: 240px"
          @keyup.enter.native="btnSearch"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParam.status"
          placeholder="字典状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dicts.sys_normal_disable"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="createTimeValue"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="btnSearch">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPerm="['system:dict:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPerm="['system:dict:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPerm="['system:dict:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPerm="['system:dict:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          v-hasPerm="['system:dict:remove']"
        >刷新缓存</el-button>
      </el-col>
    </el-row>


    <el-table :data="tableData.rows" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="字典编号" width="80"  align="center" prop="dictId" />
      <el-table-column label="字典名称"   align="center" prop="dictName" :show-overflow-tooltip="true" />
      <el-table-column label="字典类型"   align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
           <el-tooltip class="item" effect="dark" :content="'点击查看['+scope.row.dictName+']的详情'" placement="top-start">
               <router-link :to="'/system/dictdata/index/' + scope.row.dictId" class="link-type">
                 <span>{{ scope.row.dictType }} </span>
               </router-link>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
           <DictTag :dataArray="dicts.sys_normal_disable" :value="scope.row.status"></DictTag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPerm="['system:dict:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPerm="['system:dict:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

   <el-pagination v-if="tableData.total>0" :current-page="queryParam.page" :page-sizes="[10, 20,30,50]"
     :page-size="queryParam.size" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total"
     @size-change="handleSizeChange" @current-change="handleCurrentChange" />

  <!-- 添加或修改参数配置对话框 -->
   <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body :close-on-click-modal="false"
     :before-close="cancelForm">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="字典名称" prop="dictName">
          <el-input v-model="form.dictName" placeholder="请输入字典名称" />
        </el-form-item>
        <el-form-item label="字典类型" prop="dictType">
          <el-input v-model="form.dictType" placeholder="请输入字典类型" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dicts.sys_normal_disable"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancelForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>

  </div>
</template>

<script>
  import {dataListApi, addApi, editApi,deleteApi, findByIdApi, refreshCache} from '@/api/dicttype.js'
  import PageMinix from '@/mixin/PageMixin.js'
  import AddOrEditMixin from '@/mixin/AddOrEditMixin.js'
  import DictDataMinix from '@/mixin/DictDataMinix.js'
  export default {
    mixins: [DictDataMinix, PageMinix, AddOrEditMixin],
    dicts: ['sys_normal_disable'],
    data() {
      return {
        fetchDataApi: dataListApi,
        addApi: addApi,
        editApi: editApi,
        deleteByIdApi: deleteApi,
        findByIdApi: findByIdApi,
        primaryKey: 'dictId',
        // 表单校验
        rules: {
          dictName: [
            { required: true, message: "字典名称不能为空", trigger: "blur" }
          ],
          dictType: [
            { required: true, message: "字典类型不能为空", trigger: "blur" }
          ]
        }
      }
    },
    methods: {
     initFormValue() {
       this.form = {
         status: '0'
       }
     },
     // 导出excel
     handleExport(){

     },
     //刷新redis缓存
     handleRefreshCache(){
       refreshCache().then(resp=> {
          this.$message({ type: 'success', message: '操作成功!' })
       })
     }
    },
    created(){
      this.initFormValue()
    }
  }
</script>

<style scoped>
  .link-type{
    color: red;
  }
</style>
